package com.cdl.library.util;

import android.content.Context;
import android.media.AudioManager;

/***
 * 音量控制类
 */
public class VoiceManager {

    private static VoiceManager instance;

    public static VoiceManager getInstance(Context context) {
        if (instance == null) {
            synchronized (VoiceManager.class) {
                if (instance == null) {
                    instance = new VoiceManager(context);
                }
            }
        }
        return instance;
    }

    Context context;
    AudioManager audioManager;

    public VoiceManager(Context context) {
        this.context = context;
        audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    public int getCurrentVoiceNum() {
        int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        return currentVolume;
    }

    public int getMacVoiceNum() {
        int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        return maxVolume;
    }

    public void adjustVolume(int direction) {
        audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    }

}
